package com.feicheng.lanniao.service.impl;

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feicheng.lanniao.entity.HouseBuyInfo;
import com.feicheng.lanniao.entity.HouseBuyOwner;
import com.feicheng.lanniao.exception.SystemException;
import com.feicheng.lanniao.mapper.HouseBuyInfoMapper;
import com.feicheng.lanniao.result.ResultInfo;
import com.feicheng.lanniao.service.IHouseBuyInfoService;
import com.feicheng.lanniao.service.IHouseBuyOwnerService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author feichengTech
 * @since 2021-09-07
 */
@Service
public class HouseBuyInfoServiceImpl extends ServiceImpl<HouseBuyInfoMapper, HouseBuyInfo>
		implements IHouseBuyInfoService {

	@Autowired
	private IHouseBuyOwnerService iHouseBuyOwnerService;
	//新增买房
	@Override
	public ResultInfo add(String tel,String wxNumber,String title, String detail, Integer clientId) {
		if(null ==clientId || clientId==0) {
			throw new SystemException("clientId不能为空");
		}
		if (null == tel || tel.length() != 11) {
			throw new SystemException("请输入11位手机号");
		}
		if (null == wxNumber) {
			throw new SystemException("请输入微信号");
		}
		HouseBuyInfo houseBuyInfo = new HouseBuyInfo();
		houseBuyInfo.setClientId(clientId);
		houseBuyInfo.setTitle(title);
		houseBuyInfo.setDetail(detail);
		houseBuyInfo.setTel(tel);
		houseBuyInfo.setWxNumber(wxNumber);
		this.save(houseBuyInfo);
		HouseBuyOwner houseBuyOwner = new HouseBuyOwner(); 
		houseBuyOwner.setClientId(clientId);
		houseBuyOwner.setHouseBuyId(houseBuyInfo.getHouseBuyId());
		iHouseBuyOwnerService.save(houseBuyOwner);
		return ResultInfo.success();
	}

	// 删除买卖房信息
	@Override
	public Boolean remove(Integer houseBuyId) {
		HouseBuyInfo houseBuyInfo = this.getById(houseBuyId);
		houseBuyInfo.setDelFlg(false);
		return this.updateById(houseBuyInfo);
	}

	//修改详细信息	
	@Override
	public Boolean edit(Integer houseBuyId, String title, String detail,String tel,String wxNumber, Integer clientId
			) {
		HouseBuyInfo houseBuyInfo = this.getById(houseBuyId);
		houseBuyInfo.setTitle(title);
		houseBuyInfo.setDetail(detail);
		houseBuyInfo.setTel(tel);
		houseBuyInfo.setWxNumber(wxNumber);
		return this.updateById(houseBuyInfo);
	}

}
